package com.witmore.skyline.web.controller.enums;

import lombok.Getter;

@Getter
public enum WitmoreErrorCode {
    // 通用错误码
    SUCCESS(200, "成功"),
    SYSTEM_ERROR(500, "系统繁忙，请稍后再试"),
    PARAM_ERROR(501, "参数错误"),
    UNAUTHORIZED(401, "未登录"),
    // 三方接口调用失败
    THIRD_PARTY_API_ERROR(520, "远程接口调用失败"),


    // 业务错误码
    NO_DATA(1000, "暂无数据"),
    USR_NAME_PASSWORD_EMPTY(1001, "用户名密码不能为空"),
    USER_NOT_EXIST(1002, "用户不存在"),
    USER_PASSWORD_ERROR(1003, "密码错误"),
    USER_UNBIND_PROJECT(1004, "用户未关联项目"),
    ADMIN_TYPE_ERROR(1005, "账户类型异常"),
    TOKEN_INVALID(1006, "Token 无效"),
    CAMERA_NOT_EXIST(1007, "摄像头信息不存在"),
    CAMERA_GET_FAIL(1008, "摄像头信息获取失败"),
    ADMIN_GET_FAIL(1009, "管理员信息获取异常"),
    START_DATE_AFTER_END_DATE(1011, "开始日期不能大于结束日期"),
    DATE_INTERVAL_NOT_ALLOWED_7(1012, "日期时间间隔不允许超过7天"),
    DATE_INTERVAL_NOT_ALLOWED_30(1013, "日期时间间隔不允许超过30天"),
    END_DATE_AFTER_NOW(1014, "结束时间不能大于当前时间"),
    CAMERA_OFF_LINE(1015, "摄像头不在线"),
    CAMERA_CAPTURE_TASK_FAIL(1016, "摄像头抓图任务失败"),
    CAMERA_TYPE_ERROR(1017,"摄像头类型有误" ),
    PROJECT_NAME_EXIST(1018, "项目名称已存在"),

    PARENT_PROJECT_NOT_EXIST(1019, "父项目不存在"),

    PROJECT_HAVE_BUSINESS_DATA(1020, "项目下有业务数据，不能删除"),

    GEOCODE_ERROR(1021, "获取地址失败"),
    CAMERA_OFFLINE(1022, "摄像头离线"),
    CAMERA_BIND_EXIST(1023, "摄像头已绑定");

    private final int code;
    private final String message;

    WitmoreErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据错误码查找对应的枚举
     *
     * @param code 错误码
     * @return 对应的枚举
     */
    public static WitmoreErrorCode fromCode(int code) {
        for (WitmoreErrorCode errorCode : WitmoreErrorCode.values()) {
            if (errorCode.getCode() == code) {
                return errorCode;
            }
        }
        throw new IllegalArgumentException("未知的错误码: " + code);
    }
}
